//
//  MacroOfTool.h
//  BaseProject
//
//  Created by 小崔 on 2022/4/20.
//

#ifndef MacroOfTool_h
#define MacroOfTool_h


#ifdef DEBUG
#define MyLog(...) NSLog(__VA_ARGS__)
#else
#define MyLog(...)
#endif

//开发的时候打印，但是发布的时候不打印的NSLog
#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"\n⚠️ 文件名:%s\n第%d行\t函数名:%s\n日志:%s\t🔚\n\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithUTF8String:__PRETTY_FUNCTION__] UTF8String], [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])
#else
#define NSLog(...)
#endif

// 获取Info.plist文件中的值
#define InfoPlistForKey(key)  [[[NSBundle mainBundle] infoDictionary] objectForKey:key]
// 获取客户端版本号信息
#define CRJ_CLIENT_VERSION InfoPlistForKey(@"CFBundleShortVersionString")
// 获取Build信息
#define CRJ_BUILD_VERSION  InfoPlistForKey(@"CFBundleVersion")

#define SCREEN_WIDTH     [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT    [[UIScreen mainScreen] bounds].size.height

// 等比例缩放 lx 子View离父View左边的距离
#define CRJ_Height(imgW, imgH, lx)  (SCREEN_WIDTH-lx*2)/imgW*imgH

#define ScaleWidth(value)   (((value)/375.0/1) * SCREEN_WIDTH)
#define ScaleHeight(value)  (((value)/812.0/1) * SCREEN_HEIGHT)


#define IS_IPHONEX \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})

//顶部导航栏h高度
#define CRJ_NAVIGATIONBAR_HEIGHT  (IS_IPHONEX ? 88.0 : 64.0)
//底部tabbar高度
#define CRJ_TABBAR_HEIGHT         (IS_IPHONEX ? 83.0 : 49.0)
//IphoneX底部高度
#define CRJ_XBOTTOM_HEIGHT        (IS_IPHONEX ? 34.0 : 0.0)
//IphoneX底部高度
#define CRJ_VIDEOHOMEVCXB        (IS_IPHONEX ? 34.0 : 20.0)
// 精确状态栏的高度
#define CRJ_STATE_HEIGHT [[UIApplication sharedApplication] statusBarFrame].size.height
// 精确导航栏的高度
#define CRJ_NAVIGATIONBAR [GlobalTool topViewController].navigationController.navigationBar.frame.size.height
// 精确导航栏和状态栏的高度
#define CRJ_NAVIGATIONBAR_AND_STATUSBARHEIGHT [GlobalTool topViewController].navigationController.navigationBar.frame.size.height + [[UIApplication sharedApplication] statusBarFrame].size.height
// 精确tabar的高度
#define CRJ_TABAR_HEIGHT self.tabBarController.tabBar.frame.size.height

#define WS(weakSelf)      __weak __typeof(&*self)    weakSelf  = self;    //弱引用
#define StrongSelf(strongSelf)  __strong __typeof(&*self) strongSelf = weakSelf;//强引用


// HexColor
#define HexColor(hexStr) [UIColor colorWithHexString:hexStr]
#define kUIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0  green:((float)((rgbValue & 0xFF00) >> 8))/255.0  blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define kUIColorFromRGBA(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0  green:((float)((rgbValue & 0xFF00) >> 8))/255.0  blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]
#define RGBALPHAColor(a, r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]
#define RGB(r, g, b) kARGBColor(255, (r), (g), (b))

#define FontRegular(font)   [UIFont fontWithName:@"PingFangSC-Regular" size:font]
#define FontMedium(font)   [UIFont fontWithName:@"PingFangSC-Medium" size:font]
#define FontBold(font)   [UIFont fontWithName:@"PingFangSC-Semibold" size:font]

/**
 执行block 不用判断是否为nil
 
 @param block block名称
 @param ...   参数
 
 @return 执行
 */
#define BLOCK_EXEC(block, ...) if (block) { block(__VA_ARGS__); };

// block
#define weakify(var) \
try {} @catch (...) {} \
__weak __typeof__(var) var ## _weak = var;


#define strongify(var) \
try {} @catch (...) {} \
__strong __typeof__(var) var = var ## _weak;


//沙箱缓存路径
#define DIR_PATH_FOR_CACHE  NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0]

//获取本地图片
#define IMAGE(name)         [UIImage imageNamed:name]
//图片拉伸方法
#define ResizableImageForMode(name,top,left,bottom,right,mode) [IMAGE(name) resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right) resizingMode:mode]

/** xib创建 */
#define BundleToIndexObj(nibName,index)    [[NSBundle mainBundle] loadNibNamed:nibName owner:nil options:nil][index]

/** 跳转设置页面 */
#define PUSH_SETUP_SYS      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]

#endif /* MacroOfTool_h */
